{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "23dc2785",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dotenv:  E:\\work\\code\\ai\\.env\n"
     ]
    }
   ],
   "source": [
    "from openai import OpenAI\n",
    "from dotenv import load_dotenv, find_dotenv\n",
    "\n",
    "def get_openai_key():\n",
    "    print(\"dotenv: \",find_dotenv())\n",
    "    _ = load_dotenv(find_dotenv())\n",
    "    return OpenAI()\n",
    "\n",
    "client = get_openai_key()\n",
    "\n",
    "def get_completion(prompt, model=\"gpt-3.5-turbo\",temperature = 0):\n",
    "    response = client.chat.completions.create(\n",
    "        model=model,\n",
    "        messages= [\n",
    "            {\n",
    "                \"role\": \"user\",\n",
    "                \"content\": prompt,\n",
    "            }\n",
    "    ],\n",
    "        temperature=temperature\n",
    "    )\n",
    "    return response.choices[0].message[\"content\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "070c3c05",
   "metadata": {},
   "outputs": [],
   "source": [
    "fact_sheet_chair = \"\"\"\n",
    "概述\n",
    "\n",
    "    美丽的中世纪风格办公家具系列的一部分，包括文件柜、办公桌、书柜、会议桌等。\n",
    "    多种外壳颜色和底座涂层可选。\n",
    "    可选塑料前后靠背装饰（SWC-100）或10种面料和6种皮革的全面装饰（SWC-110）。\n",
    "    底座涂层选项为：不锈钢、哑光黑色、光泽白色或铬。\n",
    "    椅子可带或不带扶手。\n",
    "    适用于家庭或商业场所。\n",
    "    符合合同使用资格。\n",
    "    \n",
    "结构\n",
    "\n",
    "    五个轮子的塑料涂层铝底座。\n",
    "    气动椅子调节，方便升降。\n",
    "\n",
    "尺寸\n",
    "\n",
    "    宽度53厘米|20.87英寸\n",
    "    深度51厘米|20.08英寸\n",
    "    高度80厘米|31.50英寸\n",
    "    座椅高度44厘米|17.32英寸\n",
    "    座椅深度41厘米|16.14英寸\n",
    "\n",
    "选项\n",
    "\n",
    "    软地板或硬地板滚轮选项。\n",
    "    两种座椅泡沫密度可选：中等（1.8磅/立方英尺）或高（2.8磅/立方英尺）。\n",
    "    无扶手或8个位置PU扶手。\n",
    "\n",
    "材料\n",
    "外壳底座滑动件\n",
    "\n",
    "    改性尼龙PA6/PA66涂层的铸铝。\n",
    "    外壳厚度：10毫米。\n",
    "    座椅\n",
    "    HD36泡沫\n",
    "\n",
    "原产国\n",
    "\n",
    "    意大利\n",
    "\"\"\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "099148aa-e242-4cae-a887-5a8df794a5bb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "产品描述：\n",
      "\n",
      "我们自豪地推出美丽的中世纪风格办公家具系列，包括文件柜、办公桌、书柜、会议桌等。这个系列提供多种外壳颜色和底座涂层选择，让您可以根据个人喜好和装饰风格进行定制。您可以选择塑料前后靠背装饰或全面装饰，底座涂层选项包括不锈钢、哑光黑色、光泽白色或铬。椅子可选择带或不带扶手，适用于家庭或商业场所，并符合合同使用资格。\n",
      "\n",
      "这款椅子采用五个轮子的塑料涂层铝底座，配有气动椅子调节功能，方便您进行高度调节。尺寸为宽度53厘米、深度51厘米、高度80厘米，座椅高度44厘米、座椅深度41厘米。\n",
      "\n",
      "我们提供软地板或硬地板滚轮选项，两种座椅泡沫密度可选，以及无扶手或8个位置PU扶手选择。材料方面，外壳底座滑动件采用改性尼龙PA6/PA66涂层的铸铝，外壳厚度为10毫米，座椅采用HD36泡沫。\n",
      "\n",
      "这款产品原产国为意大利，为您的办公空间增添优雅的中世纪风格，让您享受舒适的工作体验。立即选购，让您的办公室焕然一新！\n"
     ]
    }
   ],
   "source": [
    "prompt = f\"\"\"\n",
    "您的任务是帮助营销团队给予技术说明创建一个产品的营销描述\n",
    "\n",
    "根据 ```标记的说明书提供的信息，编写一个产品描述。\n",
    "技术说明： ```{fact_sheet_chair}```\n",
    "\"\"\"\n",
    "response = get_completion(prompt)\n",
    "print(response.content)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "743b3863-eb4f-457d-9041-b3c1ee470d74",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "介绍我们的中世纪风格办公家具系列，包括文件柜、办公桌、书柜等。多种颜色和装饰选择，适用于家庭或商业场所。结构稳固，座椅可调节高度，座椅泡沫密度可选。意大利制造，符合合同使用资格。\n"
     ]
    }
   ],
   "source": [
    "prompt = f\"\"\"\n",
    "您的任务是帮助营销团队给予技术说明创建一个产品的营销描述\n",
    "\n",
    "根据 ```标记的说明书提供的信息，编写一个产品描述。\n",
    "使用最多50个词。\n",
    "\n",
    "技术说明： ```{fact_sheet_chair}```\n",
    "\"\"\"\n",
    "response = get_completion(prompt)\n",
    "print(response.content)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ed6779ab-4df3-48cc-9d4d-c416834d2c8b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "89"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(response.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8ccf9966-d6f9-4a90-b65b-9a37d02d8c3e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "这款中世纪风格办公家具系列采用改性尼龙PA6/PA66涂层的铸铝外壳底座，配有气动椅子调节和可选的座椅泡沫密度。底座涂层可选不锈钢、哑光黑色、光泽白色或铬。适用于家庭或商业场所，符合合同使用资格。产地意大利。\n"
     ]
    }
   ],
   "source": [
    "prompt = f\"\"\"\n",
    "您的任务是帮助营销团队给予技术说明创建一个产品的营销描述\n",
    "\n",
    "根据 ```标记的说明书提供的信息，编写一个产品描述。\n",
    "该描述面向家具零售商因此应具有技术性质，并侧重于产品材料结构。\n",
    "使用最多50个词。\n",
    "\n",
    "技术说明： ```{fact_sheet_chair}```\n",
    "\"\"\"\n",
    "response = get_completion(prompt)\n",
    "print(response.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "373c08d3-a694-4f5d-8835-94b42a09d7a1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "这款中世纪风格办公家具系列包括文件柜、办公桌、书柜等，适用于家庭或商业场所。底座涂层可选不锈钢、哑光黑色、光泽白色或铬。椅子可选带或不带扶手，座椅高度44厘米，座椅深度41厘米。材料包括改性尼龙PA6/PA66涂层的铸铝和HD36泡沫。产品id: SWC-110.\n"
     ]
    }
   ],
   "source": [
    "prompt = f\"\"\"\n",
    "您的任务是帮助营销团队给予技术说明创建一个产品的营销描述\n",
    "\n",
    "根据 ```标记的说明书提供的信息，编写一个产品描述。\n",
    "该描述面向家具零售商因此应具有技术性质，并侧重于产品材料结构。\n",
    "在该描述末尾，包括技术规格中7个字符的产品id\n",
    "使用最多50个词。\n",
    "\n",
    "技术说明： ```{fact_sheet_chair}```\n",
    "\"\"\"\n",
    "response = get_completion(prompt)\n",
    "print(response.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "56e5a963-4056-4319-8248-fe47571a23b8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "这款中世纪风格办公家具系列的椅子结构坚固，采用改性尼龙PA6/PA66涂层的铸铝外壳底座，配有五个轮子和气动调节功能。可选座椅泡沫密度和扶手位置，适用于家庭或商业场所。尺寸为宽53厘米，深51厘米，高80厘米，座椅高度44厘米，座椅深度41厘米。产品id：SWC-100。\n",
      "\n",
      "| 产品尺寸       | 英寸测量值  |\n",
      "|----------------|------------|\n",
      "| 宽度           | 20.87      |\n",
      "| 深度           | 20.08      |\n",
      "| 高度           | 31.50      |\n",
      "| 座椅高度       | 17.32      |\n",
      "| 座椅深度       | 16.14      |\n"
     ]
    }
   ],
   "source": [
    "prompt = f\"\"\"\n",
    "您的任务是帮助营销团队给予技术说明创建一个产品的营销描述\n",
    "\n",
    "根据 ```标记的说明书提供的信息，编写一个产品描述。\n",
    "该描述面向家具零售商因此应具有技术性质，并侧重于产品材料结构。\n",
    "在该描述末尾，包括技术规格中7个字符的产品id\n",
    "在描述之后，生产一个表格，提供产品尺寸，表格应该有两列，一列包括尺寸名称，第二列包括英寸的测量值。\n",
    "给表格命名为\"产品尺寸\"。\n",
    "\n",
    "使用最多50个词。\n",
    "\n",
    "技术说明： ```{fact_sheet_chair}```\n",
    "\"\"\"\n",
    "response = get_completion(prompt)\n",
    "print(response.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c17941c7-8eb2-48a8-be81-f3087c583b83",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "```html\n",
      "<div>\n",
      "    <p>这款中世纪风格办公家具系列包括文件柜、办公桌、书柜、会议桌等，适用于家庭或商业场所。结构稳固，座椅高度可调，座椅可选不同泡沫密度和扶手位置。外壳底座采用改性尼龙PA6/PA66涂层的铸铝，座椅采用HD36泡沫。产品ID: SWC-100</p>\n",
      "</div>\n",
      "\n",
      "<table>\n",
      "    <caption>产品尺寸</caption>\n",
      "    <tr>\n",
      "        <td>宽度</td>\n",
      "        <td>20.87英寸</td>\n",
      "    </tr>\n",
      "    <tr>\n",
      "        <td>深度</td>\n",
      "        <td>20.08英寸</td>\n",
      "    </tr>\n",
      "    <tr>\n",
      "        <td>高度</td>\n",
      "        <td>31.50英寸</td>\n",
      "    </tr>\n",
      "    <tr>\n",
      "        <td>座椅高度</td>\n",
      "        <td>17.32英寸</td>\n",
      "    </tr>\n",
      "    <tr>\n",
      "        <td>座椅深度</td>\n",
      "        <td>16.14英寸</td>\n",
      "    </tr>\n",
      "</table>\n",
      "```\n"
     ]
    }
   ],
   "source": [
    "prompt = f\"\"\"\n",
    "您的任务是帮助营销团队给予技术说明创建一个产品的营销描述\n",
    "\n",
    "根据 ```标记的说明书提供的信息，编写一个产品描述。\n",
    "该描述面向家具零售商因此应具有技术性质，并侧重于产品材料结构。\n",
    "在该描述末尾，包括技术规格中7个字符的产品id\n",
    "在描述之后，生产一个表格，提供产品尺寸，表格应该有两列，一列包括尺寸名称，第二列包括英寸的测量值。\n",
    "给表格命名为\"产品尺寸\"。\n",
    "\n",
    "使用最多50个词。\n",
    "将所有内容格式化为可用于网站的HTML格式，将描述放在<div>元素中\n",
    "\n",
    "技术说明： ```{fact_sheet_chair}```\n",
    "\"\"\"\n",
    "response = get_completion(prompt)\n",
    "print(response.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "e7e62e6a-32bc-493a-9a91-ca06e8dac352",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "```html\n",
       "<div>\n",
       "    <p>这款中世纪风格办公家具系列包括文件柜、办公桌、书柜、会议桌等，适用于家庭或商业场所。结构稳固，座椅高度可调，座椅可选不同泡沫密度和扶手位置。外壳底座采用改性尼龙PA6/PA66涂层的铸铝，座椅采用HD36泡沫。产品ID: SWC-100</p>\n",
       "</div>\n",
       "\n",
       "<table>\n",
       "    <caption>产品尺寸</caption>\n",
       "    <tr>\n",
       "        <td>宽度</td>\n",
       "        <td>20.87英寸</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "        <td>深度</td>\n",
       "        <td>20.08英寸</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "        <td>高度</td>\n",
       "        <td>31.50英寸</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "        <td>座椅高度</td>\n",
       "        <td>17.32英寸</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "        <td>座椅深度</td>\n",
       "        <td>16.14英寸</td>\n",
       "    </tr>\n",
       "</table>\n",
       "```"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#以HTML格式展示处理，加载\n",
    "from IPython.display import display, HTML\n",
    "display(HTML(response.content))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2fe7471d-2ada-471d-aef1-0927cdf813da",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.21"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
